﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Xpo;
using BusinessObjects;
using System.Linq;

namespace UI
{
    public partial class frmLinhVuc_Edit : FormBase
    {
        public frmLinhVuc_Edit()
        {
            InitializeComponent();
        }

        public LinhVuc ItemEdit { get; set; }

        private void frmLinhVuc_Edit_Load(object sender, EventArgs e)
        {
            try
            {
                txtTen.DataBindings.Add(new Binding("Text", ItemEdit, "TenLinhVuc"));
                txtMoTa.DataBindings.Add(new Binding("Text", ItemEdit, "MoTa"));
            }
            catch (Exception ex)
            {
                CommonError(ex);
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (CheckInput())
                {
                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                CommonError(ex);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {
                this.Close();
            }
            catch (Exception ex)
            {
                CommonError(ex);
            }
        }

        private bool CheckInput()
        {
            bool result = true;
            dxErrorProvider1.ClearErrors();
            if (txtTen.Text == string.Empty)
            {
                dxErrorProvider1.SetError(txtTen, "Chưa nhập");
                result = false;
            }
            return result;
        }
    }
}